<?php
/**
 * User: xialei
 * Date: 2016/7/2 0002
 * Time: 14:38
 */

namespace app\modules\api\controllers;


use app\models\News;
use yii\rest\Controller;
use yii\web\NotFoundHttpException;

class NewsController extends Controller
{
    /**
     * 查看文章
     * @param $id
     * @return null|static
     * @throws NotFoundHttpException
     */
    public function actionView($id)
    {
        $news = News::findOne($id);
        if (empty($news)) {
            throw new NotFoundHttpException('文章不存在');
        }
        $news->createdAt = date('Y-m-d',$news->createdAt);
        return $news;
    }
}